package cn.itcast.hotel.listener;

import cn.itcast.hotel.constants.MQConstants;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Xiao
 * @version 1.0
 * @description 酒店数据消息监听器
 * @date 2021/11/12
 */
@Component
public class HotelListener {
    @Autowired
    private IHotelService hotelService;

    /**
     * 监听新增或修改业务
     * @param id
     */
    @RabbitListener(queues = MQConstants.HOTEL_INSERT_QUEUE)
    public void hotelInsertOrUpdateListener(Long id) {
        System.err.println("监听到新增/修改业务，id：" + id);
        hotelService.insertById(id);
    }

    /**
     * 监听删除业务
     * @param id
     */
    @RabbitListener(queues = MQConstants.HOTEL_DELETE_QUEUE)
    public void hotelDeleteListener(Long id) {
        System.err.println("监听到删除业务，id：" + id);
        hotelService.deleteById(id);
    }
}
